document.getElementById("username").focus()
document.getElementById("save").onclick=function(){
	var data={}
	data.username=$("#username").val()
	data.number=$("#id").val()
	data.site=$("#site").val()
	data.chinese_name=""
	data.user_type="记账单位"
	data.password=$("#password").val()
	if(/^ *$/.test(data.username)){
		showErrorInfo("请填写手机号！")
		return false;
	}
	else if(data.username.length!==11){
		showErrorInfo("手机号位数不正确 ！")
		return false;
	}
	else if(/^ *$/.test(data.number)){
		showErrorInfo("请填写单位名称！")
		return false;
	}
	data=JSON.stringify(data)
	$.ajax({
		"url":"/user_admin/",
		"error":errorAjax,
		"beforeSend":start_load_pic,
		"complete":stop_load_pic,
		"data":{"data":data},
		"type":getQ().type,
		"success":function(data){
			if(responseCheck(data)){
				alert("操作成功！")
				window.opener.location.reload()
				window.close()
			}
		}
	})
	
}
if(getQ().action==="general"){
	$("#showType").hide()
	$("#showSite").hide()
}
else{
	$("#showType").show()
	$("#showSite").show()
}
$.ajax({
		"url":"/site_admin/",
		"error":errorAjax,
		"beforeSend":start_load_pic,
		"complete":stop_load_pic,
		"dataType":"jsonp",
		"success":function(data){
			if(responseCheck(data)){
				if(data.content.length===0){
					alert("系统中还没有加油站，请创建以后再操作！")
					window.close()
				}
				for(var i=0;i<data.content.length;i++){
					var select=document.getElementById("site")
					var option=document.createElement("option")
					option.textContent=data.content[i].name
					option.setAttribute("value",data.content[i].name)
					select.appendChild(option)
					
				}

				if(data.user_type==="站长"){
					$(select).val(data.my_site).attr("disabled",true)
				}
				try{
				var _data=getQ().data
				console.log(_data)
				_data=JSON.parse(_data)
				$("#username").val(_data.username)
				$("#id").val(_data.number)
				$("#site").val(_data.site)
				}
				catch(e){
					console.log("不做数据加载")
				}
			}
		}
	})
	
if (getQ().type==="PUT"){
	$("#username").attr("readonly",true)
}
